<?php
error_reporting(0);
if(isset($_GET['mode'])) header('Content-type: image/svg+xml');
$acceptLang = stripos($_SERVER['HTTP_ACCEPT_LANGUAGE'], 'zh-CN') !== false ? 'cn' : 'en';
$acceptLang = isset($_GET['lang']) ? $_GET['lang'] : $acceptLang;
$acceptLang = htmlspecialchars($acceptLang, ENT_QUOTES);

if(isset($_GET['mode']) and $_GET['mode'] == 'getlogo'){
}

$host = 'localhost:33061';  // MySQL主机
$dbname = 'zentao';  // 数据库名
$username = 'root';  // 用户名
$password = 'My@123';  // 密码


try {
    $dsn = "mysql:host=$host;dbname=$dbname;charset=utf8";  // 数据源名称
    $options = [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,  // 设置错误处理模式为异常模式
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,  // 设置默认的结果集获取模式为关联数组模式
    ];

    $pdo = new PDO($dsn, $username, $password, $options);  // 创建PDO对象
    //echo "连接成功！";
} catch (PDOException $e) {
    echo "连接失败: " . $e->getMessage();exit;
}

$task_arr = [];


$data = json_decode(file_get_contents("php://input"),true);


$search = $data["search"];


switch($search["status"]) {
	case "wait":
		$where .= " and t.`status`='wait' ";
		break;
	case "done":
		$where .= " and t.`status`='done' ";
		break;
	case "doing":
		$where .= " and t.`status`='doing' ";
		break;
	case "closed":
		$where .= " and t.`status`='closed' ";
		break;
	default:
		exit;
}
$sql = "SELECT p.`name` as project_name, t.* FROM zt_task t LEFT JOIN zt_project p on t.project = p.id where 1=1 {$where} ORDER BY t.id desc limit 100;";


$result = $pdo->query($sql);
while ($row = $result->fetch()) {
	$task_arr[] = $row;
    //echo "用户名：" . $row['username'] . "，邮箱：" . $row['email'] . "<br>";
}

echo json_encode($task_arr);

?>